package com.sf.osms.dep.processor.handler.dynamicexcjava;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.sf.osms.dep.domain.AgentConfig;
import com.sf.osms.dep.processor.exception.ExceptionConstants;
import com.sf.osms.dep.processor.exception.RouterException;
import com.sf.osms.dep.processor.util.CollectionUtil;


public class DynamicExecUtil {
	
	private static ConcurrentMap<String, Object> proxyMapRule = new ConcurrentHashMap<String, Object>();
	
	public static Object getDynamicObject(String dynamicName,String src) throws Exception{
		
		DynamicEngine de = DynamicEngine.getInstance();
	    Object instance  = null;
		instance =  de.javaCodeToObject(dynamicName,src.toString());
		if(instance == null){
			throw new RouterException(ExceptionConstants.DYNAMIC_JAVA_COMPILE_ERROR_CODE, ExceptionConstants.DYNAMIC_JAVA_COMPILE_ERROR_INFO);
		}
		return instance;
	}
	
	public static void setDynamicObject(String dynamicName,String src) throws Exception{
		Object object = proxyMapRule.get(dynamicName);
		if(null != object){
			DynamicEngine de = DynamicEngine.getInstance();
		    Object instance  = null;
			instance =  de.javaCodeToObject(dynamicName,src.toString());
			if(instance == null){
				throw new RouterException(ExceptionConstants.DYNAMIC_JAVA_COMPILE_ERROR_CODE, ExceptionConstants.DYNAMIC_JAVA_COMPILE_ERROR_INFO);
			}
			proxyMapRule.put(dynamicName, instance);
		}
	}
	
	
	public static void setDynamicObject(List<AgentConfig> agentCofigs) throws Exception{
		
		if(CollectionUtil.isEmpty(agentCofigs)){
			return;
		}
		
	}
	public static void main(String[] args) throws Exception{
		
	}
}
